package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing")
@Api(tags = "护理计划管理")
public class NursingProjectPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;


    @GetMapping("/plan/search")
    @ApiOperation(value = "分页查询护理计划" ,notes = "分页查询护理计划")
    public ResponseResult selectByPage(
           @ApiParam(value = "护理计划名称") String name,
           @ApiParam(value = "护理计划状态0-禁用  1-启用") Integer status,
           @ApiParam(value = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
           @ApiParam(value = "每页显示的条数") @RequestParam(defaultValue = "10")  Integer pageSize
    ){
        PageResponse<NursingPlanVo> pageResponse =   nursingPlanService.selectByPage(name,status,pageNum,pageSize);

        return success(pageResponse);
    }


    @PostMapping("/plan")
    @ApiOperation(value = "新增护理计划" ,notes = "新增护理计划")
    public ResponseResult add(@ApiParam(value = "护理计划") @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.add(nursingPlanDto);

        return success();
    }

    @GetMapping("/plan/{id}")
    @ApiOperation(value = "根据id查询护理计划带有护理项目" ,notes = "根据id查询护理计划带有护理项目")
    public ResponseResult getById(@ApiParam(value = "护理计划id") @PathVariable("id") Long id ){
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);

        return success(nursingPlanVo);
    }


    @PutMapping("/plan/{id}")
    @ApiOperation(value = "修改护理计划" ,notes = "修改护理计划")
    public ResponseResult update(@ApiParam(value = "护理计划") @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.update(nursingPlanDto);

        return success();
    }


    @DeleteMapping("/plan/{id}")
    @ApiOperation(value = "删除护理计划" ,notes = "根据id删除护理计划")
    public ResponseResult delete(@ApiParam(value = "护理计划id") @PathVariable("id") Long id ){
        nursingPlanService.delete(id);

        return success();
    }
}
